<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="id" name="id" th:value="${tiku.id}" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">题库名字：</label>
                            <div class="col-sm-8">
                                <input id="tkname" name="tkname" th:value="${tiku.tkname}" class="form-control" type="text" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">库类型：</label>
                            <div class="col-sm-8">
                                <input id="tktype" name="tktype" class="form-control" type="text" th:value="${tiku.tktype}"
                                       placeholder="可填入多个类型用&quot;,&quot;隔开" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">库年份：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="tkyear" th:value="${tiku.tkyear}" name="tkyear" placeholder="YYYY" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">缩略图：</label>
                            <div class="col-sm-8">
                                <input id="filepath" name="filepath" class="form-control" type="hidden" th:value="${tiku.filepath}">
                                <button type="button" class="layui-btn" id="test1">
                                    <i class="fa fa-cloud"></i>上传文件
                                </button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">预览：</label>
                            <div class="col-sm-8">
                                <img class="layui-upload-img" id="demo1" width="200px" height="200px" th:src="${tiku.filepath}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">库描述：</label>
                            <div class="col-sm-8">
                                <textarea id="tkexplain" name="tkexplain" th:value="${tiku.tkexplain}" class="form-control" ></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler: function () {
            update();
        }
    });

    function update() {
        $.ajax({
            cache: true,
            type: "POST",
            url: "/contract/tiku/update",
            data: $('#signupForm').serialize(),// 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });

    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: icon + "请输入名字"
                }
            }
        })
    }
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1', //绑定元素
            url: '/common/sysFile/upload', //上传接口
            size: 1000,
            accept: 'file',
            done: function (r) {
                $("#filepath").val(r.fileName);
                $('#demo1').attr('src', r.fileName); //图片链接（base64）
                layer.msg(r.msg);

            },
            error: function (r) {
                layer.msg(r.msg);
            }
        });
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#tkyear'
            , type: 'year'
        });
    });
</script>
</body>
</html>
